<?php
/**
 * 微博后台管理项目 媒体表数据层

 */
define("CACHE_PREFIX_MBLOG_RT_MID","_mblog_rt_mid_");

class db_mblog_rt_mid extends db_base
{
	var $table_name  ="mblog_rt_mid";
	
	function get_item_by_mid($mid)
	{
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_MBLOG_RT_MID."-get_item_by_mid-{$mid}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,1,1,"","mid='{$mid}' and status=1");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	function insert_mblog_rt_mid($mid,$cron_endtime)
	{
		$ary = array();
		$ary["mid"] = $mid;
		$ary["cron_endtime"] = $cron_endtime;
		
		$ary["status"] = 1;
		
		$res = $this->insert($this->table_name,$ary,"",true);
		
		
		return $res;
	}
	
	
	function update_by_mid($mid,$status="")
	{
		$where = "mid = $mid";
		$ary = array();

		if(strlen($status)>0)$ary["status"] = $status;
		
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
		
	}
	
	
	
	
	function cron_update_by_id($mid,$order_level="",$last_get_min_id="")
	{
		$where = "mid = $mid";
		$ary = array();

		if(strlen($order_level)>0)$ary["order_level"] = "order_level+{$order_level}" ;
		if(strlen($last_get_min_id)>0)$ary["last_get_min_id"] = $last_get_min_id;
		
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
		
	}
	
	
	function cron_get_mid_count($id)
	{
		$now = time();
		$id = intval($id);
		$where = "id > {$id} and  status =1 and cron_endtime > $now ";
		$content = $this->get_listcount($this->table_name, $where);
		
		return $content;
	}
	
	
	
	function cron_get_mid_list($id,$p=1,$pcount=20)
	{
		$id = intval($id);
		$now = time();
		$where = "id > {$id} and  status =1 and cron_endtime > $now";
		$content = $this->get_alllist($this->table_name,$p,$pcount, "  id ", $where);
		
		return $content;
	}
	

	
	
	function cron_get_mid_list_order_by_level($p=1,$pcount=20)
	{
		$now = time();
		$id = intval($id);
		$where = " status =1 and cron_endtime > $now";
		$content = $this->get_alllist($this->table_name,$p,$pcount, "order_level", $where);
		
		return $content;
	}
	
	

	


}
